package com.example.readbook.Utils;


import android.content.Context;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.WindowManager;
import android.widget.Toast;

import com.example.readbook.MyApp;

import java.math.BigDecimal;

/**
 * Package    : com.zjedu.xueyuan.utils
 * ClassName  : yxs的工具类
 * Description: $yxs的工具
 * Author     : 坐怀不乱
 * Date       : 2018/5/5 17:01
 */
public class Utils {

    private static String CacheFilePath = "";


    /**
     * 获取显示指标
     * @param context
     *         上下文
     * @return DsisplayMetrics
     */
    private static DisplayMetrics getDisplayMetrics(Context context) {
        WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        Display display = windowManager.getDefaultDisplay();
        DisplayMetrics displayMetrics = new DisplayMetrics();
        display.getMetrics(displayMetrics);
        return displayMetrics;
    }

    /**
     * 获取屏幕的宽度
     * @param context
     *         上下文
     * @return WindowWidth
     */
    public static int getWindowWidght(Context context) {
        return getDisplayMetrics(context).widthPixels;
    }

    /**
     * 获取屏幕的高度
     * @param context
     *         上下文
     * @return WindowHeight
     */
    public static int getWindowHeight(Context context) {
        return getDisplayMetrics(context).heightPixels;
    }

    public static Toast toast = null;

    public static void showToast(String msg) {
        if (toast == null)
            toast = Toast.makeText(MyApp.mContext, msg, Toast.LENGTH_SHORT);
        else
            toast.setText(msg);
        toast.show();
    }

    //保留一位小数
    public static double m2(double f, int size) {
        return new BigDecimal(f).setScale(size, BigDecimal.ROUND_HALF_UP).doubleValue();
    }


}